import java.util.ArrayList;

/**
 * 
 */

/**
 * @author mmolina
 *
 */
public class CalculateStatistics {
	private ArrayList<ProcessBookkeeping> processesBookkeeping;
	private double averageResponseTime;
	private double averageWaitingTime;
	private double averageTurnaroundTime;
	private double averageTotalCPUTime;

	public CalculateStatistics(ArrayList<ProcessBookkeeping> processesBookkeeping){
		this.processesBookkeeping = processesBookkeeping;
		this.run();
	}
	
	public void run(){
		int j = 1;
		for(ProcessBookkeeping book: processesBookkeeping){
			System.out.printf("Process %d times:\n", j);
			System.out.println("\tResponse:\t " + book.getFirstResponseTime());
			System.out.println("\tTotal CPU:\t " + book.getTotalCPUTime());
			System.out.println("\tTurnaround:\t " + book.getTurnaroundTime());
			System.out.println("\tWaiting:\t " + book.getWaitingTime() + "\n");
			this.averageResponseTime += book.getFirstResponseTime();
			this.averageTotalCPUTime += book.getTotalCPUTime();
			this.averageTurnaroundTime += book.getTurnaroundTime();
			this.averageWaitingTime += book.getWaitingTime();
			++j;
		}
		
		this.averageResponseTime /= this.processesBookkeeping.size();
		this.averageTotalCPUTime /= this.processesBookkeeping.size();
		this.averageTurnaroundTime /= this.processesBookkeeping.size();
		this.averageWaitingTime /= this.processesBookkeeping.size();
	}

	/**
	 * @return the averageResponseTime
	 */
	public double getAverageResponseTime() {
		return averageResponseTime;
	}

	/**
	 * @return the averageWaitingTime
	 */
	public double getAverageWaitingTime() {
		return averageWaitingTime;
	}

	/**
	 * @return the averageTurnaroundTime
	 */
	public double getAverageTurnaroundTime() {
		return averageTurnaroundTime;
	}

	/**
	 * @return the averageTotalCPUTime
	 */
	public double getAverageTotalCPUTime() {
		return averageTotalCPUTime;
	}
}
